//
//  NewCityDynTwoImageCell.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/9/20.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit
import SDWebImage

class NewCityDynTwoImageCell: BaseTableViewCell {
    
    @IBOutlet weak var topTimeLabel: UILabel!
    @IBOutlet weak var topBottomMargin: NSLayoutConstraint!
    
    @IBOutlet weak var littleImageView: UIImageView!
    @IBOutlet weak var bottomLabel: UILabel!
    @IBOutlet weak var imageTopLabel: UILabel!
    @IBOutlet weak var indetorView: UIActivityIndicatorView!
    @IBOutlet weak var bigImageView: UIImageView!
    @IBOutlet weak var timeBgView: UIView!
    
    @IBOutlet weak var lineView: UIView!
    @IBOutlet weak var middleBottomMargin: NSLayoutConstraint!
    
    @IBOutlet weak var bigImageViewH: NSLayoutConstraint!
    @IBOutlet weak var bottomMargin: NSLayoutConstraint!
    
    @IBOutlet weak var borderBgView: UIView!
    
    @IBOutlet weak var tuoMingView: UIView!
    
    var model : NewCityDynamicModel? {
        
        didSet{
            
            if model == nil {
                return
            }
            
            if let imageCach = SDWebImageManager.shared().imageCache {
                
                if let tempImage = imageCach.imageFromDiskCache(forKey: model?.message_cover)  {
                    
                    bigImageViewH.constant = tempImage.size.height / tempImage.size.width * (KScreenW - 60)
                    
                    
                    bigImageView.image = tempImage
                    
                }else{
                    
                    bigImageViewH.constant = (KScreenW - 60) / 16 * 9
                    
                    bigImageView.sd_setImage(with: URL(string :model!.message_cover), placeholderImage: UIImage.defaulImage(), options: .progressiveDownload) { (image, _, _, _) in
                        
                    }
                    
                }
                
                
                
            }else{
                
                
                bigImageViewH.constant = (KScreenW - 60) / 16 * 9
                
                bigImageView.sd_setImage(with: URL(string :model!.message_cover), placeholderImage: UIImage.defaulImage(), options: .progressiveDownload) { (image, _, _, _) in
                    
                }
                
                
            }
            
            imageTopLabel.text = model?.message_title
            
            topTimeLabel.text = model?.message_time
            
            bottomLabel.text = model?.subMessage_list.first?.subMessage_title
            
            littleImageView.sd_setImage(with: URL(string :model!.subMessage_list.first!.subMessage_cover), placeholderImage: UIImage.defaulImage())
            
            
            
            
        }
    
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        
        contentView.backgroundColor = UIColor.viewBgGrey()
        
        borderBgView.addCornerAndBorder(borderColor: UIColor.gray, borderWidth: 0.6, masksToBounds: true, cornerRadius: 5)
        
        timeBgView.addCornerAndBorder(borderColor: nil, borderWidth: 0, masksToBounds: true, cornerRadius: 3)

        lineView.backgroundColor = UIColor.lineGray()
        
        topBottomMargin.constant = 0
        
        middleBottomMargin.constant = 0
        
        
        bottomMargin.constant = 0
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
